<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>网站信息</title>
    <link rel="stylesheet" href="__CSS__/pintuer.css">
    <link rel="stylesheet" href="__CSS__/admin.css">
    <link rel="stylesheet" href="__STATIC__/css/layui.css">
    <script src="__STATIC__/layui.js"></script>
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 部门信息</strong>&emsp;<a
            style="color: #3a4bfb;font-weight: bold " href="javascript:history.go(-1)">返回上一步</a></div>
    <br>
    <form class="layui-form" action="{:url('Branch/index')}" method="post">
        <div style="margin-top: 1%; margin-left: 1%" class="layui-form-item">
            <div class="layui-inline">
                <label style="float: left;margin-top: 10px" class="layui-form-lable">主体：</label>
                <div class="layui-input-inline">
                    <select name="region_id" id="region_id" lay-filter="region_id" lay-search="">
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label style="float: left;margin-top: 10px" class="layui-form-lable">部门：</label>
                <div class="layui-input-inline">
                    <select name="branch_id" id="branch_id" lay-filter="branch_id" lay-search="">
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label style="float: left;margin-top: 10px" class="layui-form-lable">姓名：</label>
                <div class="layui-input-inline">
                    <input placeholder="请输入你要搜索的部门负责人" type="text" name="ch_name" id="ch_name" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div style="float: right;margin-right: 10%" class="layui-input-block">
                <button id="submit" class="layui-btn" name="submit" value="submit" lay-submit="" lay-filter="demo">
                    立即搜索
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <table id="demos" lay-filter="test">
        <thead>
        <tr>
            <th lay-data="{field: 'id', align: 'center', title: 'ID', width: '14%', sort: true}"></th>
            <th lay-data="{field: 'region', align: 'center', title: '所属主体', width: '27%', sort: true}"></th>
            <th lay-data="{field: 'branch', align: 'center', title: '部门', width: '16%', sort: true}"></th>
            <th lay-data="{field: 'ch_name', align: 'center', title: '部门负责人', width: '16%', sort: true}"></th>
            <th lay-data="{fixed: 'right', width: '25%', align: 'center',title:'操作', toolbar: '#barDemo'}"></th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr>
            <td>{if condition="$vo.id eq null"}无{else /}{$vo.id}{/if}</td>
            <td style="text-align: left">{if condition="$vo.region eq null"}无{else /}{$vo.region}{/if}</td>
            <td>{if condition="$vo.branch eq null"}无{else /}{$vo.branch}{/if}</td>
            <td>{if condition="$vo.ch_name eq null"}无{else /}{$vo.ch_name}{/if}</td>
            <td lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

    <!-- 这里同样支持 laytpl 语法，如： -->
    {{#  if(d.auth > 2){ }}
    <a class="layui-btn layui-btn-mini" lay-event="check">审核</a>
    {{#  } }}
</script>
<script>
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table
            , form = layui.form
            , layer = layui.layer;
        //加载
        var index = layer.load(1, {time: 10*1000});
        //关闭
        layer.close(index);
        var num = 0;
        $.getJSON("{:url('Base/liandong_c')}", function (data_a) {
            $.each(data_a.datalist, function (i, item) {
                if (i == 0) {
                    num = item.id
                }
                $('#region_id').append("<option value=" + item.id + ">" + item.region + "</option>");
            });
            $.getJSON("{:url('Base/liandong_d')}?region_id=" + num, function (data_b) {
                $.each(data_b.datalist, function (j, res) {
                    $('#branch_id').append("<option value=" + res.id + ">" + res.branch + "</option>")
                });
                form.render('select');
            })
        });
        form.on('select(region_id)', function (data_aa) {
            var region_ids = data_aa.value;
            $('#branch_id').html('');
            $.getJSON("{:url('Base/liandong_d')}?region_id=" + region_ids, function (data_bb) {
                $.each(data_bb.datalist, function (i, item) {
                    $('#branch_id').append('<option  value=' + item.id + '>' + item.branch + "</option>");
                });
                form.render('select');
            })
        });
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.init('test', {
            //设置高度
            height: 400
            //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
//支持所有基础参数
            , page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
                , curr: 1
            }
        });
        //方法渲染table
        /*table.render({
         elem: '#demos'
         , height: 315
         , url: "{:url('Branch/indexlist')}" //数据接口
         , page: true //开启分页
         , cols: [[ //表头
         {field: 'id', align: 'center', title: 'ID', width: '14%', sort: true}
         , {field: 'region', align: 'center', title: '主体', width: '16%'}
         , {field: 'branch', align: 'center', title: '部门', width: '16%', sort: true}
         , {field: 'ch_name', align: 'center', title: '部门负责人', width: '16%'}
         , {fixed: 'right', width: '36%', align: 'center',title:'操作', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
         ]]
         });*/
        //监听工具条(修改删除查看)
        //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        table.on('tool(test)', function (obj) {
            //获得当前行数据
            var data = obj.data;
            //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var layEvent = obj.event;
            //获得当前行 tr 的DOM对象
            var tr = obj.tr;
            //查看
            if (layEvent === 'detail') {
                //do somehing//删除
            } else if (layEvent === 'del') {
                //layer.confirm('真的删除行么', function (index) {
                //删除对应行（tr）的DOM结构，并更新缓存
                del(data.id);
                //layer.close(index);
                //向服务端发送删除指令
                // });
                // 编辑
            } else if (layEvent === 'edit') {
                //do something
                window.location.href = "{:url('Branch/branchsave')}" + "?id=" + data.id;
                //同步更新缓存对应的值
                /*obj.update({
                 username: '123'
                 , title: 'xxx'
                 });*/
            }
        });
    })
</script>
<script>
    function del(id) {
        //插件表格删除
        layui.use(['layer'], function () {
            var layer = layui.layer;
            layer.confirm('你确定要删除吗', {icon: 7, title: '提示'}, function (index) {
                var submit = "submit";
                $.ajax({
                    type: "post",
                    url: "{:url('Branch/branchdel')}",
                    data: {"id": id},
                    dataType: "json",
                    success: function (a) {
                        //alert(10);
                        if (a) {
                            layer.msg('删除成功', {icon: 1});
                            layer.close(index);
                        } else {
                            layer.msg('删除失败', {icon: 2});
                            layer.close(index);
                        }
                        setTimeout(function () {
                            //使用  setTimeout（）方法设定定时2000<a href="https://www.baidu.com/s?wd=%E6%AF%AB%E7%A7%92&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWuHn4n1DkmynYmhu9uhcd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHf4PWmsrHRdnWckPWnkrHmkrf" target="_blank" class="baidu-highlight">毫秒</a>
                            window.location.reload();//页面刷新
                        }, 2000);
                    }

                })
            })

        });
        //表格删除
        /*if (confirm("您确定要删除吗?")) {
         $.ajax({
         type: "post",
         url: "{:url('Stafflist/staffdel')}",
         data: {"id": id},
         dataType: "json",
         success: function (a) {
         if (a) {
         alert("删除成功");
         window.location.replace("{:url('Stafflist/index')}")
         } else {
         alert("删除失败")
         }
         }
         })
         }*/
    }
</script>
</body>
</html>